/**
 * @Author：ming
 * @Date：2023/9/26 12:45 PM
 * @Filename：Lc219
 */

import java.util.HashMap;

/**
 * @author ming
 */
public class Lc219 {
    public boolean containsNearbyDuplicate(int[] nums, int k) {
        HashMap<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
           if(map.containsKey(nums[i])){
               if(Math.abs(map.get(nums[i])-i)<=k){
                   return true;
               }else {
                   map.put(nums[i],i );
               }
           }else {
               map.put(nums[i],i);
           }
        }

        return false;
    }
}
